package com.hbtt.sousou;


/**
 * @author 刘世博
 * 话唠套餐类
 *
 */
public class TalkPackage extends ServicePackage implements SendService, NetService, CallService {
	
	private int talkTime; // 通话时间
	private int smsCount; // 短信条数
	private int flow; // 上网流量
	private double price; // 套餐月资费
	
	public TalkPackage() {
		
	}
	public TalkPackage(int talkTime, int flow, int smsCount, double price) {
		this.talkTime = talkTime;
		this.smsCount = smsCount;
		this.flow = flow;
		this.price = price;
	}

	public double getPrice() {
		return price;
	}

	public int getTalkTime() {
		return talkTime;
	}

	public void setTalkTime(int talkTime) {
		this.talkTime = talkTime;
	}

	public int getSmsCount() {
		return smsCount;
	}

	public void setSmsCount(int smsCount) {
		this.smsCount = smsCount;
	}

	public int getFlow() {
		return flow;
	}

	public void setFlow(int flow) {
		this.flow = flow;
	}

	public void showInfo() {
		 System.out.println("话痨套餐：通话时长为"+talkTime+"分钟/月，"+"短信条数为"+smsCount+"条/月。");  
	}
	
	public int call(int minCount, MobileCard card) throws Exception{
		int temp = minCount;
		for (int i = 0; i < minCount; i++) {
			// 如套餐内剩余分钟数减要使用的分钟数大于等于1的话
			if (talkTime - card.getRealTalkTime() >= 1) {
				// 就给card中的realtalktime赋值加1
				card.setRealTalkTime(card.getRealTalkTime() + 1);
			} else if (card.getMoney() >= 0.2) {
				// 如果话费大于等于0.2的话
				card.setRealTalkTime(card.getRealTalkTime() + 1);
				// 话费减0.2 打一分钟
				card.setMoney(card.getMoney() - 0.2);
				// 为消费总额加0.2
				card.setConsumAmount(card.getConsumAmount() + 0.2);
			} else {
				temp = i;//记录实现通话的分钟数
				throw new Exception("本次已通话"+i+"分钟，余额不足，请充值后再使用！");
			}
		}
		return temp;
	}

	public int send(int count, MobileCard card) throws Exception {
		int temp = count;
		for (int i = 0; i < count; i++) {
			if (smsCount - card.getRealSMSCount() >= 1) {
				card.setRealSMSCount(card.getRealSMSCount() + 1);
			} else if (card.getMoney() >= 0.1) {
				card.setRealSMSCount(card.getRealSMSCount() + 1);
				card.setConsumAmount(card.getConsumAmount() + 0.1);
				card.setMoney(card.getMoney() - 0.1);
			} else {
				temp = i;
				throw new Exception("您已经发送了"+i+"条短信，余额不足，请充值后再使用！");
			}
		}
		return temp;
	}

	public int netPlay(int flow, MobileCard card) throws Exception{
		int temp = flow;
		for (int i = 0; i < flow; i++) {
			if (this.flow - card.getRealFlow() >= 1) {
				card.setRealFlow(card.getRealFlow() + 1);
			} else if (card.getMoney() >= 0.1) {
				card.setRealFlow(card.getRealFlow() + 1);
				card.setMoney(card.getMoney() - 0.1);
				card.setConsumAmount(card.getConsumAmount() + 0.1);
			} else {
				temp = i;
				throw new Exception("您已经使用了"+i+"MB流量，余额不足，请充值后再使用！");
			}
		}
		return temp;
	}
}




